package com.biomatch.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.biomatch.domain.Teacher;
import com.biomatch.dto.Pagination;
import com.biomatch.response.RestResponse;
import com.biomatch.response.RestResult;
import com.biomatch.service.TeacherService;
import com.biomatch.utils.Internationalize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("dance.teacher")
@RequestMapping("/teacher")
@Api(value = "街舞老师管理")
public class TeacherController {
    @Autowired
    private Internationalize internationalize;

    @Autowired
    private TeacherService teacherService;

    @RequestMapping(value="/getAllByPage", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取老师信息", response = Teacher.class, httpMethod = "POST")
    public RestResult<Teacher> getAllByPage(@RequestBody Pagination pagination) {
        IPage<Teacher> result=teacherService.getAllByPage(pagination);
        return RestResponse.success(result);
    }

    @RequestMapping(value="/getAll", method = RequestMethod.POST)
    @ApiOperation(value = "获取全部舞种", response = Teacher.class, httpMethod = "POST")
    public RestResult<List<Teacher>> getAll() {
        List<Teacher> result =teacherService.getAll();
        return RestResponse.success(result);
    }

    @RequestMapping(value="/saveOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "新增或更新舞种", response = Teacher.class, httpMethod = "POST")
    public RestResult<Teacher> saveOrUpdate(@RequestBody Teacher teacher) {
        Teacher result = teacherService.saveOrUpdate(teacher);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("position.name.repeat"));
        } else {
            return RestResponse.success(result);
        }
    }

    @RequestMapping(value="/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除舞种", response = Teacher.class, httpMethod = "POST")
    public RestResult<Teacher> delete(@RequestBody Teacher teacher ) {
        Teacher result = teacherService.delete(teacher);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("position.status.used"));
        } else {
            return RestResponse.success(result);
        }
    }

}
